package com.kathir.database.utils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class History {

	public static void main(String[] args) throws IOException {		
		
			try {
				
			Class.forName("com.mysql.jdbc.Driver");
			Connection connect = DriverManager.getConnection("jdbc:mysql://localhost/kathir?user=root&password=gowtham");
			Statement statement = connect.createStatement();
			System.out.println("Enter the Device ID");
			BufferedReader brObj= new BufferedReader(new InputStreamReader(System.in));
			String value = brObj.readLine();
			int n = Integer.parseInt(value);
			System.out.println("Enter the Device Name");
			BufferedReader brObj1= new BufferedReader(new InputStreamReader(System.in));
			String value1 = brObj1.readLine();
			String temp = "INSERT INTO DEVICE_MASTER (DEVICE_NO,DEVICE_NAME) VALUES ("+n+",'"+value1+"')";
			System.out.println(temp);
			statement.execute(temp);
			ResultSet resultSet = statement.executeQuery("select * from history");
			
			while(resultSet.next()){
				System.out.println("S No : "+resultSet.getString("S_No"));
				System.out.println("DEVICE_NO : "+resultSet.getString("DEVICE_NO"));
				System.out.println("VILLAGE_CODE : "+resultSet.getString("VILLAGE_CODE"));
				System.out.println("BRANCH_CODE : "+resultSet.getString("BRANCH_CODE"));
				System.out.println("RECEIVED_FROM : "+resultSet.getString("RECEIVED_FROM"));
				System.out.println("SENT_TO : "+resultSet.getString("SENT_TO"));
				System.out.println("DATE_RECEIVED : "+resultSet.getString("DATE_RECEIVED"));
			}
			resultSet.close();
			statement.close();
			connect.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	    
	    
	}
		
	}

	
